package com.ouc.eddyAlgorithm.service.impl;

import com.ouc.common.core.text.Convert;
import com.ouc.eddyAlgorithm.domain.VgForecast;
import com.ouc.eddyAlgorithm.mapper.VgTrackMapper;
import com.ouc.eddyAlgorithm.service.IVgTrackService;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * vg涡旋计算最终Service业务层处理
 *
 * @author b504
 * @date 2023-03-09
 */
@Service
public class VgTrackServiceImpl implements IVgTrackService {
  @Autowired
  private VgTrackMapper vgTrackMapper;

  @Autowired
  private SqlSessionFactory sqlSessionFactory;

  /**
   * 查询vg涡旋计算最终
   *
   * @param id vg涡旋计算最终主键
   * @return vg涡旋计算最终
   */
  @Override
  public VgForecast selectVgTrackById(Integer id) {
    return vgTrackMapper.selectVgTrackById(id);
  }

  /**
   * 查询vg涡旋计算最终列表
   *
   * @param vgTrack vg涡旋计算最终
   * @return vg涡旋计算最终
   */
  @Override
  public List<VgForecast> selectVgTrackList(VgForecast vgTrack) {
    return vgTrackMapper.selectVgTrackList(vgTrack);
  }

  /**
   * 新增vg涡旋计算最终
   *
   * @param vgTrack vg涡旋计算最终
   * @return 结果
   */
  @Override
  public int insertVgTrack(VgForecast vgTrack) {
    return vgTrackMapper.insertVgTrack(vgTrack);
  }

  /**
   * 修改vg涡旋计算最终
   *
   * @param vgTrack vg涡旋计算最终
   * @return 结果
   */
  @Override
  public int updateVgTrack(VgForecast vgTrack) {
    return vgTrackMapper.updateVgTrack(vgTrack);
  }

  /**
   * 批量删除vg涡旋计算最终
   *
   * @param ids 需要删除的vg涡旋计算最终主键
   * @return 结果
   */
  @Override
  public int deleteVgTrackByIds(String ids) {
    return vgTrackMapper.deleteVgTrackByIds(Convert.toStrArray(ids));
  }

  /**
   * 删除vg涡旋计算最终信息
   *
   * @param id vg涡旋计算最终主键
   * @return 结果
   */
  @Override
  public int deleteVgTrackById(Integer id) {
    return vgTrackMapper.deleteVgTrackById(id);
  }

  @Override
  public void insertByBatch(List<VgForecast> vgTrackList) {
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
    //  先获取mapper，不能使用spring提供的mapper必须从sqlSession里面拿，因为只有这里的batch才是false
    VgTrackMapper mapper = sqlSession.getMapper(VgTrackMapper.class);
    for (VgForecast vgForecast : vgTrackList) {
      mapper.insertVgTrack(vgForecast);
    }

    sqlSession.commit();
    sqlSession.clearCache();
    sqlSession.close();
  }

  @Override
  public void truncateTable() {
    vgTrackMapper.truncateTable();
  }

  @Override
  public List<VgForecast> selectAll() {
    return vgTrackMapper.selectAll();
  }
}
